local csv            = require 'lib/csv'
local create_invoice = require 'create_invoice'
local parse_data     = require 'parse_data'

local data           = {}
local counter        = 1
for fields in csv.open('source/source.csv', { header = true }):lines() do
    data[counter] = {}
    for k, v in pairs(fields) do
        data[counter][k] = v
    end
    counter = counter + 1
end

local parsed_data = parse_data(data)

for _, pd in ipairs(parsed_data) do
    create_invoice(pd.company_name, pd.company_address, pd.company_telephone, pd.company_mail, pd.invoice_number,
        pd.period, pd.client_name, pd.client_code, pd.address, pd.city, pd.meter_code, pd.solar_fee, pd.solar_kwh,
        pd.solar_chf, pd.day_fee, pd.day_kwh, pd.day_chf, pd.night_fee, pd.night_kwh, pd.night_chf, pd.meter_rent,
        pd.vat, pd.vat_amount, pd.total_without_vat, pd.total)
end
